﻿/*
作者：王伟 
作用：清空分类所包含的文章
*/
CREATE procedure  Clear_class
(
@strClassID  int=0,
@ErrInfo nvarchar(200)='' output
)
As 
declare @RsClassID  int
declare @RsChild  int
declare @RsParentPath nvarchar(200)

declare @s varchar(1000)
set @s=@strClassID
if not exists(Select ClassID,Child,ParentPath  From ArticleClass Where ClassID=@strClassID)
begin
	--print('d')
	Set @ErrInfo='栏目不存在，或者已经被删除'
	return 
end

Select @RsClassID=ClassID,@RsChild=Child,@RsParentPath=ParentPath From ArticleClass Where ClassID=@strClassID 




if @RsChild>0 
begin	
	select @s=@s+cast(classid as varchar(10))+',' from ArticleClass Where ParentID=@RsClassID
	/*
	print(@s)
	
	declare @s varchar(1000)
	declare @RsClassID  int
	declare @RsChild  int	
	Set @RsChild=2
	Set @RsClassID=4
	*/
	Select  @s= @s+cast(classid as varchar(10))+',' From ArticleClass Where ParentPath like ''+Convert(varchar(200),@RsParentPath)+','+Convert(varchar(100),@RsClassID) +',%'
end
	if(charindex(',',@s)<=0)
	begin
		Set @s=@s+','
	end 
	--print(@s)
	update Article Set isdel=1  where charindex(','+Convert(varchar(200),ClassID)+',',','+@s)>0
	Set @ErrInfo='成功'
	return 


GO
